<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2020 All rights reserved.
// +----------------------------------------------------------------------
// | User: Simony <1362229026@qq.com>
// | wechat: Shen86579595
// +----------------------------------------------------------------------

namespace app\common\model\member;

use app\common\model\Base;

use think\Config;

class MemberApply extends Base
{
    protected $name = 'member_apply';

    public $states = [ //0申请中，1通过 2拒绝 3已激活
        0 => '审核',
        1 => '已通过',
        2 => '已拒绝',
        3 => '已激活',
    ];


    public function getMemberApplyList($condition = [], $page, $field = 'm_a.*', $order = 'm_a.id asc')
    {

        $c_join_sql = $this->field('id,min(id) AS min_id,member_id')->group('member_id')->buildSql();


        $res = $this->alias('m_a')
            ->where($condition)
            ->join($c_join_sql.' c_t', 'c_t.member_id=m_a.member_id', 'left')
            ->join('area a', 'a.id=m_a.city', 'left')
            ->field($field.',if(m_a.id=c_t.min_id,1,0) as first_trial')
            ->order($order);

        if ($page == 0) {
            $res = $res->select()->toArray();
            return $res;
        } else {

            $res = $res->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $res;
            return $res->items();
        }
    }
}
